package thread;

public class ThreadInterrupt2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {//获取线程实例
                System.out.println("线程开始咯!");
                try {
                    Thread.sleep(1000);//线程可能被提前唤醒 产生异常
                } catch (InterruptedException e) {
                    //throw new RuntimeException(e);抛出另一个异常
                    e.printStackTrace();//打印调用栈
                    break;
                }
            }
            System.out.println("线程执行完成咯!");
        });
        t.start();
        Thread.sleep(3000);
        System.out.println("让t线程结束");
        t.interrupt();
    }
}
